#!/usr/bin/env python
#!coding=utf-8


import os
import time
import datetime
import sys

def timestamp2date(timestamp, pattern="%Y-%m-%d %H:%M:%S"):
    timeArray = time.localtime(timestamp)
    otherStyleTime = time.strftime(pattern, timeArray)
    return otherStyleTime

def timestamp2date_version(pattern="%Y-%m-%d %H:%M:%S"):
    # 获得当前时间
    now = datetime.datetime.now()
    delta = datetime.timedelta(days=5)
    n_days_after = now + delta
    # 转换为指定的格式
    otherStyleTime = n_days_after.strftime(pattern)
    print(otherStyleTime)

def date2timestamp(dateFormat, pattern="%Y-%m-%d %H:%M:%S"):
    timeArray = time.strptime(dateFormat, "%Y-%m-%d %H:%M:%S")
    print(timeArray)
    # timeArray可以调用tm_year等
    print(timeArray.tm_year)
    print(timeArray.tm_yday)
    # 转为时间戳
    timeStamp = time.mktime(timeArray)
    print(timeStamp)
    return timeStamp
    
if __name__ == "__main__":
    daytime = "2019-06-03 21:25:02"
    pattern="%Y-%m-%d %H:%M:%S"
    tm = time.time() #获取当前时间戳
    print("current timestamp is " + str(tm))
    dateFormat = timestamp2date(tm, pattern)
    #print(dateFormat)
    timestamp2date_version()
    date2timestamp(daytime)

